package codequity.three.demo40;

/*
匿名类的构造函数很特殊
 */
enum Ops {
    ADD, SUB;
}

class Calculator {
    private int i, j, result;

    //无参构造
    public Calculator() {
    }

    //有参构造
    public Calculator(int _i, int _j) {
        i = _i;
        j = _j;
    }

    //设置符号，是加法运算还是减法运算
    protected void setOperator(Ops _op) {
        result = _op.equals(Ops.ADD) ? i + j : i - j;

    }

    //取得运算结果
    public int getResult() {
        return result;
    }
}

public class Client40 {
    public static void main(String[] args) {
        Calculator c1 = new Calculator(1, 2) {
            {
                setOperator(Ops.ADD);
            }
        };
        System.out.println(c1.getResult());
    }

}

//沉淀，学习，破局
class Add extends Calculator {
    {
        setOperator(Ops.ADD);
    }

    //覆写父类的构造方法
    public Add(int _i, int _j) {

    }
}
